package ui.components;

import java.util.Enumeration;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;

import entities.QueryResult;

public class BarChart extends Chart {

	public BarChart(String chartTitle) {
		super(chartTitle);
	}

	@Override
	public ChartPanel getChart() {
		return chartPanel;
	}

	@Override
	protected JFreeChart createChart(Dataset dataset, String chartTitle) {
		JFreeChart chart = ChartFactory.createBarChart
				  ("","Partido", "Cantidad", (CategoryDataset) dataset, 
				   PlotOrientation.VERTICAL, true,true, false);
		  return chart;
	}

	@Override
	protected Dataset createDataset(QueryResult qResult) {
			DefaultCategoryDataset result = new DefaultCategoryDataset();
			Enumeration<String> ptdos = qResult.getPartidos();
			while(ptdos.hasMoreElements()){
				String ptdo = ptdos.nextElement();
				result.setValue(qResult.getCantVotos(ptdo), "Cantidad", ptdo);
			}			
			return result;
	}

}
